#include <iostream>
#define M 100
using namespace std;

//邻接矩阵存储结构
struct AMGraph {
    char vexs[M];
    int arcs[M][M];
    int vexnum, arcnum;
    mutable int visited[M];
};

void DFS(const AMGraph &G, int v)
{
    cout << G.vexs[v] << " ";
    G.visited[v] = 1;
    for(int i = 0; i < G.vexnum; i++)
        if(G.arcs[v][i] && !G.visited[i])
            DFS(G, i);
}

void DFSTraverse(const AMGraph &G)
{
    for(int i = 0; i < G.vexnum; i++)
        G.visited[i] = 0;
    for(int v = 0; v < G.vexnum; v++)
        if(!G.visited[v])
            DFS(G, v);
}

int main()
{
    AMGraph G = {
        {'A','B','C','D','E'},
        {
            {0, 1, 1, 0, 0},
            {0, 0, 0, 0, 1},
            {0, 1, 0, 1, 0},
            {0, 1, 0, 0, 0},
            {1, 0, 0, 1, 0},
        },
        5,
    };

    DFSTraverse(G);

    return 0;
}